package unit;

import java.util.List;

import model.Map;
import model.Tile;

import client.Client;
import util.IntPoint;
import control.Tick;
import event.AlfaEvent;
import event.AnswerEvent;
import event.UnitEvent;
import static debug.Debug.DBUG;

public class Player extends Unit{
		
	private IntPoint nextMove;
	private Map map;
	
	public Player(int id, IntPoint start, Map mapStart){
		super(id, start);
		moveAbilities.add("walk");
		map = mapStart;
		position = start;
		nextMove = start;
	}
	
	public void move(IntPoint target){
		if(position.distanceTo(target) <= 3 && standAble(target)){
			//DBUG(target);
			nextMove = target;
		}else{
			DBUG("Walking failed");
		}
	}
	
	private boolean standAble(IntPoint point){
		boolean rett = true;
		point.incX(15);
		rett = rett && map.getTileAt(point).isWalkable(this);
		point.incY(15);
		rett = rett && map.getTileAt(point).isWalkable(this);
		point.incX(-15);
		rett = rett && map.getTileAt(point).isWalkable(this);
		point.incY(-15);
		rett = rett && map.getTileAt(point).isWalkable(this);
		return rett;
	}
	
	
	public void tick(){
		position = nextMove;
	}

	public void sendUpdate(Client client) {
		client.updatedObject(this);
	}

	public Map getMap() {
		return map;
	}

	public void fireEvent(AlfaEvent event) {
	}
	
}
